<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>个人注册</title>

    <link rel="stylesheet" type="text/css" href="/static/index/css/all.css" />
    <link rel="stylesheet" type="text/css" href="/static/index/css/pages-register.css" />
    
	<script type="text/javascript" src="/static/admin/js/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="/static/index/js/all.js"></script>
	<script type="text/javascript" src="/static/index/js/pages/register.js"></script>


</head>

<body>
	<div class="register py-container ">
		<!--head-->
		<div class="logoArea">
			<a href="{:url('index/index/index')}" class=""><img src="/static/index/img/Logo.png" width="120" alt=""></a>
		</div>
		<!--register-->
		<div class="registerArea">
			<h3>注册新用户<span class="go">我有账号，去<a href="{:url('index/Login/index')}" >登陆</a></span></h3>
			<div class="info">
				<form action="{:url('index/Login/insert')}" method="post" id="reg_form" class="sui-form form-horizontal">
					{:token()}
					<div class="control-group">
						<label class="control-label">手机号：</label>
						<div class="controls">
							<input type="text" id="phone" name="phone" placeholder="请输入你的手机号" class="input-xfat input-xlarge">
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="code" class="control-label">验证码：</label>
						<div class="controls">
							<input type="text" id="code" name="code" placeholder="验证码" maxlength="4" min="4" class="input-xfat input-xlarge" style="width:120px">
							<button type="button" class="btn-xlarge" id="dyMobileButton">发送验证码</button>
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="password" class="control-label">登录密码：</label>
						<div class="controls">
							<input type="password" id="password" name="password" placeholder="设置登录密码" class="input-xfat input-xlarge">
							<span class="error"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="repassword" class="control-label">确认密码：</label>
						<div class="controls">
							<input type="password" id="repassword" name="password_confirm" placeholder="再次确认密码" class="input-xfat input-xlarge">
							<span class="error"></span>
						</div>
					</div>
					<!--<div class="control-group">
						<label for="inputPassword" class="control-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="controls">
							<input name="m1" type="checkbox" value="2" checked=""><span>同意协议并注册《品优购用户协议》</span>
						</div>
					</div>-->
					<div class="control-group">
						<label class="control-label"></label>
						<div class="controls btn-reg">
							<a id="reg_btn" class="sui-btn btn-block btn-xlarge btn-danger reg-btn" href="javascript:void(0);">完成注册</a>
						</div>
					</div>
				</form>
				<div class="clearfix"></div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机品优购</li>
				<li>销售联盟</li>
				<li>品优购社区</li>
			</ul>
			<div class="address">地址：北京市大兴区</div>
			<div class="beian">京ICP备19054611号
			</div>
		</div>
	</div>
</body>
</html>
<script>
	$(function(){

		$("#dyMobileButton").click(function(){
			// 手机号验证
			if($("#phone").val() == ""){

				$("#phone").parent().find(".error").html("不允许为空");
				return false;
			}else if(!/^1[3-9]\d{9}$/.test($("#phone").val())){

				$("#phone").parent().find('.error').html("手机号格式不正确");
				return false;
			}else{

				$("#phone").parent().find('.error').html("");
			}

			var data = {"phone":$("#phone").val()};

			$.ajax({
				url:"{:url('index/Login/sendsms')}",
				data:data,
				success:function(res){
					if(res.code != 10000)
					{
						alert(res.msg);
						return;
					}

					// 定时器
					var num = 60;
					var timer = setInterval(function(){

						num--;

						$("#dyMobileButton").html("重新发送"+num+"s").prop("disabled",true);

						if(num == 0){
							$("#dyMobileButton").html("发送验证码").prop("disabled",false);

							clearInterval(timer);
						}
					},1000)

				}
			})



		})

		// 表单验证
		$(".btn-danger").click(function(){

			var flag = true;

			// 手机号验证
			if($("#phone").val() == ""){

				$("#phone").parent().find(".error").html("不允许为空");
				flag = false;

			}else if(!/^1[3-9]\d{9}$/.test($("#phone").val())){

				$("#phone").parent().find('.error').html("手机号格式不正确");
				flag = false;

			}else{

				$("#phone").parent().find('.error').html("");
				flag = true;
			}

			// 验证码验证
			if($("#code").val() == ""){

				$("#code").parent().find(".error").html("验证码不能为空");
				flag = false;
			}else if(!/^\d{4}$/.test($("#code").val() )){

				$("#code").parent().find(".error").html("验证码格式不正确");
				flag = false;
			}else{

				$("#code").parent().find(".error").html("");
				flag = true;
			}

			if($("#password").val() == "")
			{
				$("#password").parent().find(".error").html("密码不能为空");
				flag = false;
			}else{

				$("#password").parent().find(".error").html("");
				flag = true;
			}

			if($("#repassword").val() == "")
			{
				$("#repassword").parent().find(".error").html("确认密码不能为空");
				flag = false;
			}else{

				$("#repassword").parent().find(".error").html("");
				flag = true;
			}

			if(flag){
				$("#reg_form").submit();
			}
		})
	})
</script>
